package com.liuchuanzheng.lcz_viewmove

import android.animation.Animator
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.TranslateAnimation
import android.widget.Toast
import com.google.android.material.internal.ViewUtils
import com.liuchuanzheng.lcz_viewmove.databinding.ActivityLayoutParamsBinding

@SuppressLint("RestrictedApi")
class LayoutActivity : AppCompatActivity() {
    lateinit var mViewBinding: ActivityLayoutParamsBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = ActivityLayoutParamsBinding.inflate(layoutInflater)
        setContentView(mViewBinding.root)
        //直接取宽高会不准.必须等待测量完
        mViewBinding.tvMove.post {
            mViewBinding.tvMove.apply {
                var str = "x:${x}\n    =\nleft:${left}\n    +\nTranslationX:${translationX}\n\nscrollx:${scrollX}"
                mViewBinding.tvBefore.text = str
            }
        }

        mViewBinding.tvMove.setOnClickListener {
            Toast.makeText(this, "点击", Toast.LENGTH_SHORT).show()
        }
        mViewBinding.tvMove.post {
            var l = mViewBinding.tvMove.x+ViewUtils.dpToPx(this, 50)
            var t = mViewBinding.tvMove.y
            var r = mViewBinding.tvMove.x +mViewBinding.tvMove.width+ViewUtils.dpToPx(this, 50)
            var b = mViewBinding.tvMove.y+mViewBinding.tvMove.height
            mViewBinding.btnStart.setOnClickListener {
                /**
                 * getLeft() 变
                 * getX() 变
                 * getTranslationX() 不变
                 * getScrollX() 不变
                 * 点击区域 变
                 * 是否影响其他view的位置 否
                 */


                mViewBinding.tvMove.layout(l.toInt(),t.toInt(),r.toInt(),b.toInt())
                mViewBinding.tvMove.post {
                    mViewBinding.tvMove.apply {
                        var str = "x:${x}\n    =\nleft:${left}\n    +\nTranslationX:${translationX}\n\nscrollx:${scrollX}\n点击区域: 变\n是否影响其他view的位置:否"
                        mViewBinding.tvAfter.text = str
                    }
                }
            }
        }


    }
}